layui.use(['form','jquery'], function () {

    var $ = layui.jquery;

    /*登录点击事件*/
    $("#login-btn").click(function (){
        var index = top.layer.msg('正在登陆中,请稍后',{icon:16, time:1000,shade:0.8})
        var username = $("#username").val();//账号
        var password = $("#password").val();//密码
        var vcode = $("input[name='vcode']").val();
        $.ajax({
            type: "post",
            data: {
                "username" : username,
                "password" : password,
                "vcode": vcode
            },
            url: "/login",
            success:function (res){
                console.log(res);
                if (res.state == false){
                    layer.close(index);
                    top.layer.msg(res.msg,{icon:2,time:1000});
                }else {
                    layer.close(index);
                    top.layer.msg("登录成功",{icon:1,time:1000},function (){
                        location.href="/home";
                    });
                }
            }
        })
    });
    /*点击图片切换验证码*/
    $(function() {
        $("#vcode").click(function() {
            //var url = "/captcha/captchaImage?type=math&s=" + Math.random();
            var url = "/captcha/captchaImage?type=math";
            $("#vcode").attr("src", url);
        });
    });
    /*点击刷新按钮切换验证码*/
    $(function() {
        $("#changeCode").click(function() {
            //var url = "/captcha/captchaImage?type=math&s=" + Math.random();
            var url = "/captcha/captchaImage?type=math";
            $("#vcode").attr("src", url);
        });
    });

    /*更换壁纸2*/
    $("#changeImg1").click(function (){
        $("#login-body").attr('background','/img/login/login1.jpg');
    })
    /*更换壁纸2*/
    $("#changeImg2").click(function (){
        $("#login-body").attr('background','/img/login/login2.jpg');
    })
    /*更换壁纸3*/
    $("#changeImg3").click(function (){
        $("#login-body").attr('background','/img/login/login3.jpg');
    })
    /*更换壁纸4*/
    $("#changeImg4").click(function (){
        $("#login-body").attr('background','/img/login/login4.jpg');
    })
})